<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * @abstract 生成条形码数据
 * @author zxj
 * @description
 */
class Test extends CI_Controller {
	function __construct() {
		parent::__construct();
        //分析器
        $this->output->enable_profiler(TRUE);
        $this->load->model('product_model');
        $this->load->model('material_model');
        $this->load->model('order_model');
	}

    function show($id = ''){
        $this->load->model('sftest_model');
        //$this->sftest_model->loginSf();
        $result = $this->sftest_model->oms_to_sf010($id);
        gsh_output($result);
    }





    //维修项统计
    function countItem($sTime = '',$eTime = ''){
        $this->output->enable_profiler(FALSE);
        $sTime = $sTime?$sTime:'2016-06-01';
        $eTime = $eTime?$eTime:date('Y-m-d');
        $sql = "
            select a.maintain_id,a.product_id,d.maintain_part_name,
            c.maintain_part_id,COUNT(c.maintain_part_id) as ofsize
            from maintain_product as a
            LEFT JOIN maintain_item as c on c.product_id = a.product_id
            left join maintain_part as d on d.maintain_part_id=c.maintain_part_id
            where  a.maintain_id REGEXP 'es' and a.product_model like '%iphone%'
            and (a.brand_id=67 or a.brand_id=24 or a.brand_id=73)
            and c.add_time>='$sTime' and c.add_time<='$eTime'
            GROUP BY c.maintain_part_id
        ";
        $dataList = $this->common_model->getQuery($sql,'result_array');
        $fieldData = array(
            'maintain_part_name'=>'维修项名称','maintain_part_id'=>'维修项ID','ofsize'=>'统计'
        );
        excel_output('repairItem'.$sTime.'~'.$eTime,$fieldData,$dataList);
    }




    function daochu_lq(){
        $sql = '
        select o.maintain_id,o.source_int_id,o.status_id,o.consumer_email,o.consumer_phone,o.consumer_address,
p.sku,p.maintain_id,p.product_id,p.imei,p.remark_cn,p.remark_customer,p.remark_en,p.repair_remark
from maintain_order as o left join maintain_product as p  on o.maintain_id=p.maintain_id where o.consumer_email = \'kingkingkinguno@163.com\' and o.status_id=9
        ';
        $orderAll = $this->common_model->getQuery($sql, 'result_array');
        foreach ($orderAll as &$rs) {
            $rs['repair_remark'] = strip_tags($rs['repair_remark']);
            $rs['remark_customer'] = strip_tags($rs['remark_customer']);
            $rs['remark_en'] = strip_tags($rs['remark_en']);
            $rs['remark_cn'] = strip_tags($rs['remark_cn']);
        }
        unset($rs);

        $fieldData = array(
            'maintain_id'=>'维修单号','source_int_id'=>'来源单号','status_id'=>'状态',
            'consumer_email'=>'邮箱','product_id'=>'产品ID','imei'=>'imei',
            'consumer_phone'=>'客户电话','consumer_address'=>'客户地址','sku'=>'SKU',
            'remark_cn'=>'中文备注', 'remark_en'=>'英文备注',
            'remark_customer'=>'客户备注','repair_remark'=>'维修师备注'
        );
        excel_output('lq'.time(),$fieldData,$orderAll);
    }




    function importOrder(){
        set_time_limit(0);

        //导入EXCEL类
        $this->load->library('excel/PHPExcel');
        $objReader = PHPExcel_IOFactory::createReader('Excel2007'); //use excel2007 for 2007 format Excel5
        $objReader->setReadDataOnly(true);
        $upload_file = 'resource/uploadfiles/file/excels/orderList6month.xlsx';
        $objPHPExcel = $objReader->load($upload_file);
        $objWorksheet = $objPHPExcel->getActiveSheet();
        $highestRow = $objWorksheet->getHighestRow(); //总行数
        $highestColumn = $objWorksheet->getHighestColumn();
        $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); //总列数

        gsh_output('当前导入的excel文档路径:' . FCPATH . $upload_file);
        gsh_output('excel表格信息  总行数:' . $highestRow . ' &nbsp;&nbsp; 总列数:' . $highestColumnIndex);
        gsh_output('开始进入导入start............');


        /**
         * 输出excel表格价格数据
         */
        $fieldAry = array('sku','quantity','brand','model','name');
        $productList = array();
        for ($i = 2; $i <= $highestRow; $i++) {
            $gridRows = array();
            for ($j = 0; $j < $highestColumnIndex; $j++) {
                $gridVal = $objWorksheet->getCellByColumnAndRow($j, $i)->getValue();
                $gridRows[$fieldAry[$j]] = $gridVal;
            }
            $productList[] = $gridRows;
        }

        //gsh_output($productList,1);

        //完整的产品数据
        foreach ($productList as &$rs) {
            $brandName = strtoupper($rs['brand']);
            $sql = 'select * from maintain_brand where UPPER(brand_name) like \'%'.$brandName.'%\' ';
            $brandFirst = $this->common_model->getQuery($sql,'row_array');
            if(!$brandFirst){
                $rs['brand_id'] = '37';
                $rs['other_brand_name'] = $brandName;
            }else{
                $rs['brand_id'] = $brandFirst['brand_id'];
                $rs['other_brand_name'] = $brandFirst['brand_name'];
            }
            $rs['product_model'] = $rs['model'];
            $rs['product_name'] = $rs['name'];
            $rs['product_quantity'] = 1;
            $rs['sort_id'] =1;
        }
        unset($rs);
        //完整的订单数据
        gsh_output('start insert order...........');
        //gsh_output($productList,1);
        for($i=0;$i<count($productList);$i++){
            //西班牙的退货单
            $oid = $this->order_model->createRepairId(1);
            gsh_output($oid);
            $orders['repair_site_id'] = 1;
            $orders['consumer_email'] = 'dhhtamz@outlook.com';
            $orders['consumer_phone'] = '123456789amz';
            $orders['consumer_address'] = 'amz';
            $orders['consumer_name'] = 'amz';
            $orders['maintain_type_id'] = '8';
            $orders['freight_price'] = '0';
            $orders['maintain_id'] = $oid;
            $this->order_model->addOrSetOrder($orders);
            $products = $productList[$i];
            $products['maintain_id'] = $oid;
            //gsh_output($products);
            for($j=0;$j<$products['quantity'];$j++){
                $this->product_model->addOrSetProduct($products);
            }

        }





    }






    function daochu_bw(){
        $sql = "select * from maintain_order where add_time>'2015-12-26' and add_time<'2016-01-23' and repair_site_id=2";
        $orderAll = $this->common_model->getQuery($sql, 'result_array');
        $newOrderAll = array();
        foreach ($orderAll as $rs) {
            $productList = $this->common_model->selectCustom('maintain_product',array('maintain_id'=>$rs['maintain_id']));
            foreach ($productList as $cp) {
                if(!$cp['is_guarantee']){
                    $newOrderAll[]=$rs;
                }
            }
        }
        $fieldData = array(
            'maintain_id'=>'维修单号','source_id'=>'来源单号','consumer_name'=>'客户姓名',
            'consumer_phone'=>'客户电话','consumer_email'=>'客户邮箱','consumer_address'=>'客户地址',
            'add_user'=>'添加人','add_time'=>'创建日期','repairer'=>'处理人'
        );
        excel_output('保外订单',$fieldData,$newOrderAll,'aaaa');
    }




    function daochu_wlm(){
        $sql = "select * from maintain_order where maintain_id in('es00006859','es00006583','es00007430','es00005346','es00006137','es00007778','es00005301','es00005418','es00006680','es00006745','es00007237','es00004953','es00005204','es00005291','es00005814','es00005826','es00005938','es00005955','es00006098','es00006107','es00006122','es00006186','es00006229','es00006236','es00006280','es00006319','es00006399','es00006409','es00006425','es00006493','es00006526','es00006527','es00006618','es00006633','es00006656','es00006657','es00006722','es00006724','es00006731','es00006754','es00006770','es00006786','es00006794','es00006820','es00006823','es00006848','es00006882','es00006889','es00006891','es00006921','es00006951','es00007084','es00007150','es00007202','es00007350','es00007351','es00007421','es00007515','es00007701','es00006858','es00006240','es00006241','es00006332','es00007874','es00006533','es00006919','es00006900','es00006901')";
        $orderAll = $this->common_model->getQuery($sql, 'result_array');
        foreach ($orderAll as &$rs) {
            $productList = $this->common_model->selectCustom('maintain_product',array('maintain_id'=>$rs['maintain_id']));
            $maintain_price = 0.00;
            foreach ($productList as $cp) {
                $priceData = $this->common_model->selectFirst('maintain_product_price',array('pid'=>$cp['product_id']));
                $maintain_price += $priceData['maintain_price'];
            }
            echo $maintain_price,'<br>';
        }
        unset($rs);
    }




    function insertBom(){
        //SELECT * FROM `material_group` where mg_name NOT REGEXP '(银|灰|金)' and mg_type='iphone6';
        $bomIphone5 = '主板32GB  灰,490,sku62936_pcb;主板32GB 银,490,sku62935_pcb;主板16GB 灰,430,sku49982_pcb;主板16GB 银,430,sku49983_pcb;LCM 灰,220,sku49982_lcd;LCM 银,220,sku49983_lcd;壳料（灰）,52,sku49982_shh;壳料（银）,52,sku49983_shh;尾插 灰,10,sku49982_upl;尾插 银,14,sku49983_upl;电源开机键 灰,1,sku49982_fpp;电源开机键 银,1,sku49983_fpp;音量按键 灰,2,sku49982_fpv;音量按键 银,2,sku49983_fpv;静音按键 灰,1,sku49982_ppm;静音按键 银,1,sku49983_ppm;HOM按键 灰,1,sku49982_fph;HOM按键 银,1,sku49983_fph;副摄像头,4.5,sku49982_frc;主摄像头,15,sku49982_ca;听筒,0.5,sku49982_rcv;HOME键 FPC,1,sku49982_fpb;马达,3,sku49982_mot;喇叭,4.5,sku49982_spe;WIFI天线,1,sku49982_wia;电池,18,sku49982_bat;电池贴胶,0.5,sku49982_sti;天线片,1,sku49982_gma;开机键排线,7,sku49982_cak;闪光灯罩,0.5,sku49982_fls;LCD铁片,1.5,sku49982_lsh;21个小件套,6,21个,sku49982_smp;HOM键胶套,0.5,sku49982_ruh;听筒网,0.4,sku49982_ren;定位环,0.2,sku49982_por;蓝牙天线,0.8,sku49982_bln;主板天线,1,sku49982_moe;大小垫片,0.08,sku49982_pad;尾插网,0.8,sku49982_net;螺丝,1,sku49982_Sew;包材,25,sku49982_pam';
        $bomIphone5s = '主板32GB 灰,790,sku49956_pcb;主板32GB 银,810,sku49957_pcb;主板32GB 金,810,sku49958_pcb;16GB主板 灰,650,sku49953_pcb ;16GB主板 银,650,sku49954_pcb;16GB主板 金,650,sku49955_pcb;LCM 灰,220,sku49953_lcd;LCM 银,220,sku49954_lcd ;LCM 金,220,sku49955_lcd;壳料 灰,62,sku49953_shh;壳料 银,60,sku49954_shh;壳料 金,62,sku49955_shh;home按键 灰,6,sku49953_fph;home按键 银,6,sku49954_fph;home按键 金,6,sku49955_fph ;尾插 灰,13,sku49953_upl;尾插 银,14.5,sku49954_upl;尾插 金,13,sku49955_upl;电源开机键 黑,1,sku49953_fpp;电源开机键 银,1,sku49954_fpp;电源开机键 金,1,sku49955_fpp;音量按键 黑,2,sku49953_fpv;音量按键 银,2,sku49954_fpv;音量键 金,2,sku49955_fpv;静音按键 黑,1,sku49953_ppm;静音按键 银,1,sku49954_ppm;静音按键 金,1,sku49955_ppm;主摄像头,13,sku49953_ca;副摄像头,10,sku49953_frc;电池,18,sku49953_bat;马达,5,sku49953_mot;喇叭,8,sku49953_spe;定位环,0.2,sku49953_por;天线片,1.5,sku49953_gma;WIFI天线,1.5,sku49953_wia;蓝牙天线,0.5,sku49953_bln;HOM键胶套,6,sku49953_ruh;开机键FPC（侧按键组件）,10,sku49953_fpa;LCD铁片,2.5,sku49953_lsh;听筒,2,sku49953_rcv;小件套,6.5,sku49953_smp;电池贴胶（电池仓贴纸）,2.5,sku49953_sti;螺丝,1.5,sku49953_Sew;麦克风胶套,0.2,sku49953_mis;大小垫片,0.1,sku49953_pad;包材,25,sku49953_pam';
        $bomIphone6 = '主板（16GB）,400,sku56297_pcb;LCM(LCD总成)灰,450,sku59861_lcd;LCM(LCD总成)银,450,sku56297_lcd;主摄像头,13,sku56297_ca;副摄像头,18,sku56297_frc;尾插 黑,35,sku56297_upl;尾插 银,25,sku59861_upl;音量键FPC,8,sku56297_fpf;电源开机键（灰）,2,sku59861_fpp;电源开机键（银）,2,sku56297_fpp;音量键（灰）,3,sku59861_fpv;音量键（银）,3,sku56297_fpv;静音按键（灰）,2,sku59861_ppm;静音按键（银）,2,sku56297_ppm;喇叭,10,sku56297_spe;马达,10,sku56297_mot;开机键FPC（侧按键组件）,15,sku56297_fpa;HOM键胶套,0.5,sku56297_ruh;螺丝,2.5,sku56297_Sew;小件套,12,sku56297_smp;WIFI天线,2,sku56297_wia;主板天线,2,sku56297_moe;听筒,4,sku56297_rcv;LCD铁片,8,sku56297_lsh;电池贴胶,1,sku56297_sti;电池,18,sku56297_bat;定位环,0.3,sku56297_por;听筒网,0.8,sku56297_ren;包材,35,sku56297_pam';
        $iphoneAry = array('iphone5'=>$bomIphone5,'iphone5s'=>$bomIphone5s,'iphone6'=>$bomIphone6);
        foreach ($iphoneAry as $type=>$rsStr) {
            $materialData = $this->common_model->selectFirst('material_group',array('mg_type'=>$type));
            if($materialData)continue;
            $bomAry = explode(';',$rsStr);
            foreach ($bomAry as $key=>$val) {
                list($name,$price,$sku) = explode(',',$val);
                $inData = array(
                    'mg_name'=>$name,'mg_type'=>$type,'mg_price'=>$price,'mg_number'=>1,'mg_sku'=>$sku,'add_time'=>time(),'add_user'=>'zlj'
                );
                $this->common_model->insert('material_group',$inData);
            }
        }

    }


    function daochu_track(){
        $sql = '

        SELECT t.*,s.status_name_cn,o.consumer_email FROM maintain_track as t
        left join maintain_status as s on t.target_status=s.status_id
        left join maintain_order as o on t.maintain_id=o.maintain_id
        where t.target_status>=1 and t.target_status<=4 and t.add_time>=\'2016-01-01\' and t.add_time<=\'2016-03-05\' group by t.add_time

        ';
        $dataList = $this->common_model->getQuery($sql,'result_array');

        $fieldData = array(
            'maintain_id'=>'维修单号','consumer_email'=>'客户邮箱',
            'status_name_cn'=>'处理状态','modified_user'=>'处理人','add_time'=>'处理时间'
        );
        excel_output('维修数据',$fieldData,$dataList);

    }



    function CreateOrder(){
        $productStr = 'sku49022,5,Lenovo,P780,四核手机 MTK6589 黑色;sku49090,13,Tengda,S4 MAX,S4 MAX手机 MTK6582 1G/8G 白色 单电;sku49591,4,JIAYU,G4S,佳域G4S八核版 2G/16G 黑色;sku49707,3,XIAOMI,mi 4 3G,小米米4联通3G版 16GB 白色;sku49717,1,DOOGEE,DG310,DOOGEE DG310四核 1G/8G 白色;sku49891,4,XIAOMI,mi 4 4G,小米米4联通4G版 3G/16GB 白色;sku49896,1,XIAOMI,Redmi 2,小米红米2联通4G版 1G/8G 灰色;sku49922,1,GIONEE,Elife E,金立GIONNE Elife E7高配版 3G/32G 白色 多语言;sku49973,2,XIAOMI,Redmi Note,小米 红米Note联通4G版 1GB/8GB 前黑后白 多语言;sku49984,4,Lenovo,K3 Note,联想 乐檬K3 Note联通4G版 2G/16G 白色 多语言;sku49985,1,Lenovo,K3 Note,联想 乐檬K3 Note联通4G版 2G/16G 黄色 多语言;sku49989,15,Elephone,P7000,大象P7000八核 3G/16G 5.5寸 金色;sku49990,4,Elephone,P7000,大象P7000八核 3G/16G 5.5寸 白色金边;sku49991,12,Elephone,P7000,大象P7000八核 3G/16G 5.5寸 灰色;sku56190,3,XIAOMI,redmi 1s,红米1S 四核手机 联通版 4.7寸 1+8GB 黑色;sku59326,1,XIAOMI,mi 3,小米3高通四核手机 联通版 2G/16G 5寸 白色;sku59335,1,Elephone,p2000,大象P2000手机黑色+原装大象P2000 左右翻皮套 黑色(sku59389);sku59449,4,XIAOMI,Redmi Note,小米 红米Note联通4G版 2/8GB 前黑后白 多语言;sku59584,5,ViewPad,v500,优派ViewPad V500联通移动双4G手机 2G/16G 黑色 5.5寸;sku59590,3,Elephone,s2,大象S2 黑色银边 MTK6735 2G/16G 5寸;sku59591,3,Elephone,s2 plus,大象S2 Plus 黑色银边5.5寸 MTK6735 2G/16G;sku59594,2,XIAOMI,redmi2,小米红米2移动联通双4G版 2G/16G 前黑后白;sku59601,11,Elephone,p8000,套餐A 大象P8000 3G/16G 金色;sku59611,25,Elephone,p8000,套餐A 大象P8000 3G/16G 灰色 标配;sku59614,3,MEIZU,note2,魅族魅蓝Note2 联通移动双4G版 2G/16G 白色;sku59628,11,XIAOMI,redmi2,小米红米2移动联通双4G版 2G/16G 黑色;sku59666,65,XIAOMI,4i/Mi4i,XIAOMI 4i/Mi4i 黑色手机 2G/16G 多语言;sku59673,1,Elephone,P6000 pro,大象P6000 Pro八核手机 MTK6753 2/16GB 白色 ;sku59674,2,Elephone,P6000 pro,大象P6000 Pro八核手机 MTK6753 2/16GB 黑色;sku59717,5,Elephone,P6000 pro,大象P6000 Pro八核手机3/16GB MTK6753 白色;sku59718,5,Elephone,P6000 pro,大象P6000 Pro八核手机3/16GB MTK6753 黑色;sku59743,2,Takee,1,钛客takee 1裸眼3D手机 2G/32GB 黑色 多语言;sku59760,13,ZTE,Nubia Z5 NX501,中兴努比亚Z5高通四核 2G/16G 前黑后白 多语言;sku59763,24,InFocus,M810,富可视M810高通4G手机 2G/16G 黑色;sku59798,1,XIAOMI,4i/Mi4i,XIAOMI 4i/Mi4i 黑色手机 2G/32G 多语言;sku59808,1,DOOGEE,X5 PRO,DOOGEE X5 Pro升级版 2+16GB MTK6735 黑色;sku59812,1,Takee,1,钛客takee 1裸眼3D手机 2G/32GB 白色;sku59851,1,OUKITEL,K4000,欧奇OUKITEL K4000手机 2+16GB 黑色带硅胶壳;sku59883,1,XIAOMI,MI4C,小米XIAOMI Mi4C/MI 4C高配版 3G/32G 黑色;sku59935,4,UMI,ROME,优米UMI Rome 3+16GB 金色;sku59951,2,MEIZU,note2,魅族魅蓝Note2 国际版 2+32GB 灰色;sku59953,2,MEIZU,note2,国际版16GB 魅族魅蓝note 2 灰色;sku59959,1,XIAOMI,Note3,小米红米Note 3指纹手机 高配版3+32GB 白色;sku59962,1,XIAOMI,Note3,小米红米Note 3指纹手机 标配版2+16GB 白色;sku60609,3,Elephone,p6000,大象P6000手机5寸MTK6732 64-bit 2/16GB白色;sku60648,2,Elephone,p6000,大象P6000手机5寸MTK6732 64-bit 2/16GB黑色;sku60979,5,DOOGEE,VALENCIA2 Y100 Pro,DOOGEE VALENCIA2 Y100 Pro黑色手机;sku60980,7,DOOGEE,VALENCIA2 Y100 Pro,DOOGEE VALENCIA2 Y100 Pro银色手机;sku60981,30,XIAOMI,4i/Mi4I,XIAOMI 4i/Mi4I 白色手机 2G/16G 多语言;sku61386,2,Elephone,G6,大象G6手机 黑色+柏威皮具 大象G6 左右翻皮套 黑色(sku64623);sku61387,3,Elephone,G6,大象G6手机 白色+柏威皮具 大象G6 左右翻皮套 白色(sku64622);sku61582,1,Elephone,P3000,大象P3000黑色手机 MTK6582 1GB/8GB+大象P3000S原装时钟皮套黑色(sku49834);sku61583,6,Elephone,P3000S,大象P3000S白色手机 2GB/16GB+大象P3000S用 原装时钟皮套 白色(sku49835);sku61584,8,Elephone,P3000S,大象P3000S黑色手机 2GB/16GB+大象P3000S用 原装时钟皮套 黑色(sku49834);sku61834,1,MEIZU,NOTE,魅族 魅蓝Note联通版 2G/16G 蓝色;sku62103,1,Cubot,X12,Cubot X12黑色手机;sku62113,4,MEIZU,NOTE2,魅族魅蓝Note2 联通移动双4G版 2G/16G 灰色 多语言;sku62274,3,XIAOMI,NOTE2,小米 红米Note2 双4G 高配版 2GB/32GB 黑色;sku62278,6,XIAOMI,NOTE2,小米 红米Note2 双4G 标配版 2GB/16GB 前黑后白 多语言;sku62279,2,XIAOMI,NOTE2,小米 红米Note2 双4G 标配版 2GB/16GB 全黑;sku62395,6,Elephone,M2,Elephone M2金色手机;sku62396,3,Elephone,M2,Elephone M2黑色手机;sku63627,1,JIAYU,S3,佳域S3标准版 2/16GB 5.5寸黑色;sku63628,15,JIAYU,S3,佳域S3高配版 3/16GB 5.5寸黑色;sku63797,8,ZTE,Nubia Z9 mini,努比亚小牛4 Z9 mini移动联通电信4G版 2/16G 全黑色 多语言';
        $productData = explode(';',$productStr);
        $productList = array();
        foreach ($productData as $dataStr) {
            list($sku,$quantity,$brandName,$model,$productName) = explode(',',$dataStr);
            $sql = 'select * from maintain_brand where UPPER(brand_name) like \'%'.$brandName.'%\' ';
            $brandFirst = $this->common_model->getQuery($sql,'row_array');
            if(!$brandFirst){
                $brandFirst['brand_id'] = '37';
                $brandFirst['other_brand_name'] = $brandName;
            }
            $productList[] = array(
                'sku'=>$sku,'product_model'=>$model,'product_name'=>$productName,
                'product_quantity'=>$quantity,'brand_id'=>$brandFirst['brand_id'],
                'sort_id'=>'1','other_brand_name'=>$brandFirst['other_brand_name']
            );
        }

        gsh_output($productList);
        foreach ($productList as $row) {
            //创建订单
            $orderData = array('');

        }


    }


    function update_order()
    {
        $sql = 'select * from print_barcode_list';
        $barcodeAll = $this->common_model->getQuery($sql, 'result_array');
        foreach ($barcodeAll as $rs) {
            $productFirst = $this->product_model->get_product($rs['pid']);
            $qcReportFirst = $this->product_model->getQcReport($rs['pid']);
            $attachments = $qcReportFirst['attachment'].';'.$productFirst['other_fujian_name'];
            $indata = array(
                'wgzkson'=>$productFirst['wgzkson'],'attachments'=>$attachments,
            );
            $this->common_model->update('print_barcode_list',$indata,array('pid'=>$rs['pid']));
        }

    }



/*
 *
ALTER TABLE print_barcode_list
ADD COLUMN wgzkson  varchar(255) NOT NULL COMMENT '外观状况子选项' AFTER stor_identifier,
ADD COLUMN attachments  text NOT NULL COMMENT '附件' AFTER wgzkson;
truncate table maintain_item_list;

*/
    function runsql(){
        $sql = "




        ";
        $this->db->query($sql);
    }


    /**
     * @return bool
     */
    function put_price(){
        $ids = gp('ids');
        if(empty($ids))return false;
        $sql = "
        select * from maintain_product_price WHERE pid in($ids) order by field(pid,$ids);
        ";
        $dataList = $this->common_model->getQuery($sql,'result_array');
        $service_fee_str = $acc_fee_str = $feright_fee_str = '';
        foreach ($dataList as $rs) {
            $service_fee_str .= floatval($rs['maintain_price']).',';
            $acc_fee_str .= floatval($rs['accessory_price']).',';
            $feright_fee_str .= floatval($rs['freight_price']).',';
        }
        echo $service_fee_str,'<br>';
        echo $feright_fee_str,'<br>';
        echo $acc_fee_str,'<br>';
    }


    function build_order_no2(){
        echo date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
        echo "<br>";
        echo  'WXES'.sprintf('%x',crc32(microtime()));
    }


    /***
     * 生成单号
     * @param string $prefix 唯一单号前缀
     * @return orderNumber
     */
    function build_order_no($prefix = 'wx'){
        $orderNumber = $prefix.date('ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
        return $orderNumber;
    }






    /**
     * 生成报价
     * @param string $pid 3477
     */
    function setbaojia($pid = '')
    {
        set_time_limit(0);
        $pid = intval($pid);
        if($pid){
            $productFirst = $this->common_model->selectFirst('maintain_product',array('product_id'=>$pid));
            if(!$productFirst){
                $this->common_model->delete('maintain_product_price',array('pid'=>$pid));
            }
            $priceData = $this->common_model->addPartPrice($pid);
            if(!$priceData){
                show_error('请先进行质检');
            }
            //更新报价单物料费用
            $accSum_price = '0';
            $wuliaoList = $this->material_model->get_wuliao('', $pid);
            foreach ($wuliaoList as $rs) {
                $accSum_price += intval($rs['accessory_quantity']) * floatval($rs['accessory_price']);
            }
            $priceData['accessory_price'] = $accSum_price;
            gsh_output($priceData);

            //维修项
            $partList = $this->common_model->selectCustom('maintain_item', array('product_id' => $pid));
            foreach ($partList as $rs) {
                $partIds[] = $rs['maintain_part_id'];
            }
            //获取维修项
            $sql = 'select * from maintain_part where maintain_part_id IN('.implode(',',$partIds).')';
            $partAry = $this->common_model->getQuery($sql, 'result_array');
            $partStr = '';
            foreach ($partAry as $pval) {
                $partStr .= $pval['maintain_part_name_en'] . ';';
            }
            $priceData['part'] = $partStr;
            $this->product_model->setProductPrice($pid, $priceData);
        }else {
            $productList = $this->common_model->selectCustom('maintain_product',array('add_time >'=>'2016-03-01'));
            foreach ($productList as $rs) {
                $priceData = $this->common_model->addPartPrice($rs['product_id']);
                if (!$priceData) {
                    continue;
                }
                //更新报价单物料费用
                $accSum_price = 0;
                $wuliaoList = $this->material_model->get_wuliao('', $rs['product_id']);
                foreach ($wuliaoList as $rs) {
                    $accSum_price += intval($rs['accessory_quantity']) * floatval($rs['accessory_price']);
                }
                $priceData['accessory_price'] = $accSum_price;
                gsh_output($priceData);
                $this->product_model->setProductPrice($rs['product_id'], $priceData);
            }
        }
    }





    function testPost(){
        //地址
        $url = 'http://test.cicore/maintainApi/sitesOrder/get_priceList/';
        $postData = array(
            'user' => 'zlj',
            'key' => '123456',
            'maintaininfo_ids'=>array(array('maintaininfo_id'=>1,'agree_status'=>1),array('maintaininfo_id'=>2,'agree_status'=>0),array('maintaininfo_id'=>3,'agree_status'=>1),array('maintaininfo_id'=>4,'agree_status'=>0))
        );
        //值
        $data = array('data'=>json_encode($postData));
        $result = $this->vpost($url,$data);
        echo $result;
    }



    function vpost($url, $data)
    {   // 模拟提交数据函数
        $curl = curl_init(); // 启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
        curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
        curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
        $tmpInfo = curl_exec($curl); // 执行操作
        if (curl_errno($curl)) {
            echo 'Errno' . curl_error($curl);
        }
        curl_close($curl); // 关键CURL会话
        return $tmpInfo; // 返回数据
    }





    function get_system_date($is_system = ''){
        if(!$is_system){
            //date_default_timezone_set('Etc/GMT+8');
            //date_default_timezone_set('Asia/shanghai');
            date_default_timezone_set('PRC');
        }
        gsh_output(date('Y-m-d H:i:s'));
    }



    function index(){
        $this->load->library('barcode');
        $wsdl_url = 'http://192.168.10.103:8889/webService/GetNewSkuForBackPieces.php?wsdl';
        $soap = new SoapClient(null,array('location'=>$wsdl_url,'uri'=>'GetNewSkuForBackPieces'));
        $sku='sku3980';
        $getInventoryRs = $soap->getBackPiecesSku('maintain','maintain_sys',$sku,'7成新');
        var_dump($getInventoryRs);
        echo $this->barcode->getBarcodeHTML($sku,"C128",1,30,'black','title?');
    }


    function print_tm(){
        $this->load->library('barcode');
        echo $this->barcode->getBarcodeHTML('999999999',"C128",1,30,'black','产品唯一ID');
    }


    function testPrint(){
        $this->output->enable_profiler(FALSE);
        $this->load->library('barcode');
        $barcodeList = array();
        $barcodeItem['barcode'] = $this->barcode->getBarcodeHTML('z. 222',"C128");
        $barcodeList[0] = $barcodeItem;
        $barcodeItem['barcode'] = $this->barcode->getBarcodeHTML('sku1234567898',"C128");
        $barcodeList[1] = $barcodeItem;
        $barcodeItem['barcode'] = $this->barcode->getBarcodeHTML('April 123456',"C128");
        $barcodeList[2] = $barcodeItem;
        $data['barcodeList'] = $barcodeList;
        $this->load->view('defaults/testPrint_view',$data);
    }

    function inpart(){
        $str = '';
        foreach (explode(PHP_EOL,$str) as $val) {
            list($sc,$en) =  explode('|',$val);
            $newPart[trim($sc)] = trim($en);
        }

        gsh_output($newPart);
        foreach ($newPart as $key=>$val) {
            $indata = array(
                'maintain_part_name'=>$key,'maintain_part_name_en'=>$val,
                'maintain_part_grade'=>3,'sort_id'=>2
                );
            $this->common_model->insert('maintain_part',$indata);
        }

    }


    function annaData(){
        for($i=0;$i<23;$i++) {
            //生成维修单号
            $oid = $this->order_model->createRepairId('4');
            $orderInfo['maintain_id'] = $oid;
            $orderInfo['repair_site_id'] = 4;
            $orderInfo['status_id'] = 2;
            $orderInfo['consumer_name'] = '触动力';
            $orderInfo['consumer_address'] = '触动力';
            $orderInfo['consumer_email'] = 'chudongli@chudongli.com';
            $orderInfo['consumer_phone'] = '86';
            $orderInfo['maintain_type_id'] = '6';
            $orderInfo['maintain_type_id'] = '6';
            $this->order_model->addOrSetOrder($orderInfo);
            //添加产品
            $productInfo['maintain_id'] = $oid;
            $productInfo['sort_id'] = 3;
            $productInfo['sku'] = 'sku68377';
            $productInfo['color'] = '红色';
            $productInfo['size'] = '6.5';
            $productInfo['is_bluetooth'] = '0';
            $productInfo['is_yaokong'] = '0';
            $productInfo['damage_id'] = '1';
            $pid = $this->product_model->addOrSetProduct($productInfo);
            //添加质检报告
            $qcInfo['oid'] = $oid;
            $qcInfo['pid'] = $pid;
            $qcInfo['is_description'] = 1;
            $qcInfo['damage'] = '全新';

            $this->common_model->insert('maintain_qcreport',$qcInfo);
            gsh_output('oid:'.$oid.'****pid:'.$pid);
        }
    }





}
